package leetcode_401_500;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class LeeCode_447 {
    public static void main(String[] args) {
//        System.out.println(numberOfBoomerangs(new int[][]{{0, 0}, {1, 0}, {2, 0}}));
        System.out.println(numberOfBoomerangs(new int[][]{{0,0},{1,0},{-1,0},{0,1},{0,-1}}));
    }
    private static int numberOfBoomerangs(int[][] points) {
        int ans = 0;
        for (int[] point : points) {
            Map<Integer, Integer> map = new HashMap<>();
            for (int[] p : points) {
                int dis = (point[0] - p[0]) * (point[0] - p[0]) + (point[1] - p[1]) * (point[1] - p[1]);
                map.put(dis, map.getOrDefault(dis, 0) + 1);
            }
            for (Integer key : map.keySet()) {
                Integer m = map.get(key);
                ans += m * (m - 1);
            }
        }
        return ans;
    }
}
